<template>
  <div class="user-container">
    <div class="user-header">
      <el-image
        style="width: 100px; height: 100px"
        :src="require('@/assets/header_images/userManage.png')"
      ></el-image>
      <!--此处有报错，还缺了个src='' 没有插入图片的url-->
      <div class="title">
        用户管理
        <div class="title-content">
          对系统用户账户及其权限进行创建、维护、删除等过程的统一管理，确保系统安全性、数据完整性和用户访问合规性
        </div>
      </div>
    </div>
    <div class="user-info">
      <div class="user-operate">
        <span class="keyword">关键词</span>
        <el-input
          placeholder="请输入用户名、描述"
          style="width: 20%; margin-left: 10px"
          clearable
          v-model="searchKeyword"
          @input="handleSearch"
        >
        </el-input>
        <span class="keyword" style="margin-left: 30px">角色分类</span>
        <el-select
          v-model="roleType"
          style="margin-left: 10px"
          clearable
          placeholder="请选择角色分类"
          @input="handleSearchByRoleType"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        <div class="right-menu">
          <el-button
            type="primary"
            @click="handleAddUser"
            class="el-button-primary-style"
          >
            添加
          </el-button>
        </div>
        <el-button
          v-if="multipleSelection.length"
          type="danger"
          @click="deleteSelectedRow"
          style="margin-left: 20px"
        >删除
        </el-button>
      </div>
      <div class="user-table">
        <el-table
          ref="multipleTable"
          tooltip-effect="dark"
          style="width: 100%"
          :data="tableData"
          @selection-change="handleSelectionChange"
          @row-click="handleRowClick"
          height="60vh"
        >
          <el-table-column
            type="selection"
            width="60rem"
            :selectable="checkSelectable"
            align="center"
          >
          </el-table-column>
          <el-table-column prop="username" label="用户名"
                           width="200"
          ></el-table-column>
          <el-table-column prop="roleType" label="角色" width="100">
            <template slot-scope="scope">
              {{ getRoleTypeName(scope.row.roleType) }}
            </template>
          </el-table-column>
          <el-table-column prop="createBy" label="来源"
                           width="160"
          ></el-table-column>
          <el-table-column label="用户描述">
            <template slot-scope="scope">
              <el-tooltip
                effect="dark"
                :content="scope.row.description"
                placement="bottom"
                popper-class="myTooltipClass"
                :disabled="isShowTooltip"
              >
                <div class="descSpan" style="text-align: left" @mouseover="onMouseOver($event)">
                  {{ scope.row.description }}
                </div>
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column prop="userStatus" label="状态" width="120">
            <template slot-scope="scope">
              <!--              <span style="margin-right: 2px">-->
              <!--                <svg-icon v-if="scope.row.userStatus === 0" icon-class="dotY"/>-->
              <!--                <svg-icon v-if="scope.row.userStatus === 1" icon-class="dotN"/>-->
              <!--              </span>-->
              <!--              {{ getStatusName(scope.row.userStatus) }}-->
              <el-switch
                v-model="scope.row.userStatus"
                active-color="#13ce66"
                inactive-color="#ff4949"
                :active-value="0"
                :inactive-value="1"
                :active-text="getStatusName(scope.row.userStatus)"
                @change="changeUserStatus(scope.row)"
                :disabled="!checkSelectable(scope.row)"
              >
              </el-switch>
            </template>
          </el-table-column>
          <el-table-column prop="updateTime" label="创建时间"
                           width="180"
          >
          </el-table-column>
          <el-table-column prop="updateTime" label="操作" width="240px">
            <template slot-scope="row">
              <el-button
                type="text"
                @click="editUser(row.row)"
                style="padding: 0"
                :disabled="!checkSelectable(row.row)"
              >
                编辑
              </el-button>
              <el-button
                type="text"
                @click="openEditPasswordDialog(row.row)"
                style="padding: 0; margin-right: 10px"
                :disabled="!checkSelectable(row.row)"
              >
                修改密码
              </el-button>
              <el-popconfirm
                title="此用户密码将重置为123456, 是否确认？"
                @confirm="resetPasswd(row.row.id)"
              >
                <el-button
                  type="text"
                  slot="reference"
                  style="padding: 0; margin-right: 10px"
                  :disabled="!checkSelectable(row.row)"
                >
                  重置密码
                </el-button>
              </el-popconfirm>
              <el-popconfirm
                title="此操作将永久删除该用户, 是否确认？"
                @confirm="confirmDeleteUserById(row.row)"
              >
                <el-button
                  type="text"
                  slot="reference"
                  style="padding: 0; color: #f56c6c"
                  :disabled="!checkSelectable(row.row)"
                >
                  删除
                </el-button>
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table>
        <div style="margin-top: 10px; float: right">
          <el-pagination
            background
            layout="total, prev, pager, next, jumper"
            :page-size="pagination.pageSize"
            :total="pagination.total"
            :current-page.sync="pagination.pageNum"
            @current-change="handlePageChange"
          />
        </div>
      </div>
    </div>
    <div class="add-user">
      <div>
        <el-dialog
          title="添加用户"
          width="480px"
          :visible.sync="addUserDialogVisible"
          :close-on-click-modal="false"
          :close-on-press-escape="false"
        >
          <el-form :model="addUserForm" :rules="rules" ref="addUserFormRef" label-width="100px">
            <el-form-item label="用户名称" prop="username">
              <el-input v-model="addUserForm.username"
                        placeholder="请输入4-64个字符范围内的用户名"
                        style="width: 300px"
                        clearable
              ></el-input>
            </el-form-item>
            <el-form-item label="用户角色" prop="roleType">
              <el-select
                placeholder="请选择用户角色"
                v-model="addUserForm.roleType"
                @change="changeAddRoleType"
                popper-class="el-select-dropdown-el-popper"
                style="display: inline-block; width: 300px"
              >
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                  :required="true"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="用户密码" prop="password">
              <el-input
                placeholder="请输入包含数字和字母的用户密码"
                style="width: 300px"
                clearable
                type="password"
                v-model="addUserForm.password"
                :required="true"
                show-password
              >
              </el-input>
            </el-form-item>
            <el-form-item label="用户描述" prop="description">
              <el-input
                type="textarea"
                :autosize="{ minRows: 2, maxRows: 4}"
                placeholder="请输入用户信息描述"
                style="width: 300px"
                clearable
                v-model="addUserForm.description"
              >
              </el-input>
            </el-form-item>
            <el-form-item>
              <div style="margin-left: 180px;">
                <el-button
                  type="primary"
                  size="small"
                  @click="confirmAddUser"
                  class="el-button-primary-style"
                >确定
                </el-button>
                <el-button
                  type="primary"
                  size="small"
                  @click="cancelAddUser"
                  class="el-button-primary-style"
                >取消
                </el-button>
              </div>
            </el-form-item>
          </el-form>
          <!--          <span slot="footer" class="dialog-footer">-->
          <!--            <el-button-->
          <!--              type="primary"-->
          <!--              size="small"-->
          <!--              @click="confirmAddUser"-->
          <!--              class="el-button-primary-style"-->
          <!--            >确定-->
          <!--            </el-button>-->
          <!--            <el-button-->
          <!--              type="primary"-->
          <!--              size="small"-->
          <!--              @click="cancelAddUser"-->
          <!--              class="el-button-primary-style"-->
          <!--            >取消-->
          <!--            </el-button>-->
          <!--          </span>-->
        </el-dialog>
      </div>
    </div>
    <div class="update-user">
      <div>
        <el-dialog
          title="编辑用户"
          width="480px"
          :visible.sync="updateUserDialogVisible"
          :close-on-click-modal="false"
          :close-on-press-escape="false"
        >
          <el-form :model="updateUserForm" :rules="updateUserRules" ref="updateUserFormRef" label-width="100px">
            <el-form-item label="用户名称" prop="username">
              <el-input
                placeholder="请编辑用户名称"
                disabled
                clearable
                v-model="updateUserForm.username"
                style="width: 300px"
              >
              </el-input>
            </el-form-item>
            <el-form-item label="用户角色" prop="roleType">
              <el-select
                placeholder="请编辑用户角色"
                v-model="roleTypeName"
                size="large"
                style="width: 300px"
                @change="changeUpdateRoleType"
              >
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="用户描述" prop="description">
              <el-input
                type="textarea"
                :autosize="{ minRows: 2, maxRows: 4}"
                placeholder="请输入用户信息描述"
                style="width: 300px"
                clearable
                v-model="updateUserForm.description"
              >
              </el-input>
            </el-form-item>
            <el-form-item>
              <div style="margin-left: 180px;">
                <el-button
                  type="primary"
                  size="small"
                  @click="confirmUpdateUser"
                  class="el-button-primary-style"
                >确定
                </el-button>
                <el-button
                  type="primary"
                  size="small"
                  @click="cancelUpdateUser"
                  class="el-button-primary-style"
                >取消
                </el-button>
              </div>
            </el-form-item>
          </el-form>
          <!--          <span slot="footer" class="dialog-footer">-->
          <!--            <el-button-->
          <!--              type="primary"-->
          <!--              size="small"-->
          <!--              @click="confirmUpdateUser"-->
          <!--              class="el-button-primary-style"-->
          <!--            >确定-->
          <!--            </el-button>-->
          <!--            <el-button-->
          <!--              type="primary"-->
          <!--              size="small"-->
          <!--              @click="cancelUpdateUser"-->
          <!--              class="el-button-primary-style"-->
          <!--            >取消-->
          <!--            </el-button>-->
          <!--          </span>-->
        </el-dialog>
      </div>
    </div>
    <!--修改密码-->
    <el-dialog
      title="修改用户密码"
      width="480px"
      :visible.sync="editPasswordDialogVisible"
      :close-on-click-modal="false"
      :modal-append-to-body="false"
      @close="handleCloseDialog"
      :close-on-press-escape="false"
    >
      <el-form
        :model="dataForm"
        label-width="100px"
        :rules="dataFormRules"
        ref="dataForm"
        label-position="right"
      >
        <el-form-item label="旧密码:" prop="oldpassword">
          <el-input
            class="demo-input-suffix"
            v-model="dataForm.oldpassword"
            type="password"
            auto-complete="off"
            show-password
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="新密码:" prop="newpassword" label-width="100px">
          <el-input
            class="demo-input-suffix"
            v-model="dataForm.newpassword"
            type="password"
            auto-complete="off"
            show-password
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="确认密码:"
          prop="checkpassword"
          label-width="100px"
        >
          <el-input
            class="demo-input-suffix"
            v-model="dataForm.checkpassword"
            type="password"
            auto-complete="off"
            show-password
            style="width: 300px"
          ></el-input>
        </el-form-item>

        <el-form-item>
          <div style="margin-left: 180px;">
            <el-button
              type="primary"
              size="small"
              @click="confirmEditUserPassword"
              class="el-button-primary-style"
            >确定
            </el-button>
            <el-button
              type="primary"
              size="small"
              @click="editPasswordDialogVisible = false"
              class="el-button-primary-style"
            >取消
            </el-button>
          </div>
        </el-form-item>
      </el-form>
      <!--      <div slot="footer" class="dialog-footer" style="margin-top: 5px">-->
      <!--        <el-button-->
      <!--          type="primary"-->
      <!--          @click.native="confirmEditUserPassword"-->
      <!--          class="el-button-primary-style"-->
      <!--        >确定-->
      <!--        </el-button>-->
      <!--        <el-button-->
      <!--          @click.native="editPasswordDialogVisible = false"-->
      <!--          type="primary"-->
      <!--          class="el-button-primary-style"-->
      <!--        >取消-->
      <!--        </el-button>-->
      <!--      </div>-->
    </el-dialog>
  </div>
</template>

<script>
  import {required} from "vuelidate/lib/validators";

  export default {
    name: "UserManage",
    data() {
      return {
        isShowTooltip: false,
        showDropdown: true, // 控制下拉菜单是否显示
        tableData: [],
        //这个是toggle的内容（即勾选前面的小框）
        multipleSelection: [],
        //存储当前行的用户信息
        currentUser: {},
        selectedIds: [],
        selectedStatus: [],
        searchKeyword: "",
        addUserDialogVisible: false,
        updateUserDialogVisible: false,
        editPasswordDialogVisible: false,
        tmpUserInfo: {},
        dataForm: {
          oldpassword: "",
          newpassword: "",
          checkpassword: "",
        },
        dataFormRules: {
          oldpassword: [
            {
              required: true,
              message: "请输入旧密码",
              //validator: checkOldPw,
              trigger: "blur",
            },
          ],
          newpassword: [
            {
              required: true,
              message: "请输入新密码",
              trigger: "blur",
            },
          ],
          checkpassword: [
            {
              required: true,
              message: "请输入新密码",
              //validator: checkNewPw,
              trigger: "blur",
            },
          ],
        },
        //deleteUserDialogVisible: false,
        addUserForm: {
          username: "",
          password: "",
          roleType: "",
          description: "",
        },
        roleTypeName: "",
        roleTypeMap: {},
        updateUserForm: {
          username: "",
          password: "",
          roleType: "",
          description: "",
          roleTypeName: "",
        },
        // 分页信息
        pagination: {
          total: 0,
          pageNum: 1,
          pageSize: 10,
        },
        filterKey: "",
        //角色类型
        options: [],
        roleType: "",
        //输入框校验规则
        rules: {
          username: [
            {required: true, message: "请输入用户名"},
            {
              validator: (rule, value, callback) => {
                // 自定义验证规则：只允许字母和数字，不能有空格
                const regex = /^[a-zA-Z0-9]+$/;
                if (!regex.test(value)) {
                  callback(new Error("用户名只能包含字母和数字，且不能有空格"));
                } else {
                  callback();
                }
              },
            },
            {min: 4, message: "用户名至少需要 4 个字符"},
          ],
          roleType: [
            {required: true, message: '请选择用户角色', trigger: 'change'}
          ],
          password: [
            {required: true, message: "请输入用户密码"},
            {min: 6, message: "用户密码至少需要 6 个字符"},
            {
              validator: (rule, value, callback) => {
                // 自定义验证规则：包含数字和字母
                const regex = /^(?=.*[a-zA-Z])(?=.*\d).+$/;
                if (!regex.test(value)) {
                  callback(new Error("用户密码必须包含数字和字母"));
                } else {
                  callback();
                }
              },
            },
          ],
          description: [
            {max: 254, message: "用户描述长度不超过254字符"},
          ],
        },
        updateUserRules: {
          roleType: [
            {required: true, message: '请选择用户角色', trigger: 'change'}
          ],
          description: [
            {max: 254, message: "用户描述长度不超过254字符"},
          ],
        },
      };
    },
    //必选项
    validations: {
      addUserForm: {
        username: {required},
        password: {required},
        roleType: {required},
        // 其他字段...
      },
    },
    //更新用户信息时，把角色的数字和中文进行映射
    computed: {
      roleTypeLabel: {
        //注意后端返回的options从1开始而不是从0开始
        get() {
          return this.options[this.updateUserForm.roleType - 1];
        },
        set(value) {
          this.updateUserForm.roleType =
            Object.keys(this.options).find((key) => this.options[key] === value) +
            1;
        },
      },
    },
    methods: {
      // 超级管理员用户禁止执行操作
      checkSelectable(row) {
        if (row.username === "superadmin") {
          return false;
        } else {
          return true;
        }
      },
      //选中表格的行
      toggleSelection(rows) {
        if (rows) {
          rows.forEach((row) => {
            this.$refs.multipleTable.toggleRowSelection(row);
          });
        } else {
          this.$refs.multipleTable.clearSelection();
        }
      },
      //表格选择项，获得选中的行的信息数组
      handleSelectionChange(val) {
        this.multipleSelection = val;
        this.selectedIds = val.map((row) => row.id); // 收集所有选中行的 id
        this.selectedStatus = val.map((row) => row.userStatus);
        this.currentUser = val[0];
      },
      //处理行点击事件
      handleRowClick(row) {
        this.currentUser = row; // 将当前行的数据存储在currentUser中
        // 根据 row 的某个值决定是否禁用下拉菜单
        this.showDropdown = this.isDropdownEnabled(row);
      },
      isDropdownEnabled(row) {
        // 根据 row 的某个值来判断下拉菜单是否可用
        // 示例：如果 row 的某个字段为 'superadmin'，则下拉菜单不可用
        if (row.username === "superadmin") {
          return false;
        }
        return true;
      },
      // 刷新功能函数
      handleRefresh() {
        this.fetchUserData();
      },
      // 添加用户功能函数，弹出对话框
      handleAddUser() {
        this.addUserDialogVisible = true;
        this.fetchRoleData();
      },
      // 确认添加用户
      confirmAddUser() {
        this.$refs.addUserFormRef.validate((valid) => {
          if (valid) {
            //对象的方法调用并传递参数，url已经在对象的方法中定义了
            this.$userManageApi.addUser(this.addUserForm).then((response) => {
              if (response && response.code === 200) {
                this.addUserDialogVisible = false;
                this.fetchUserData();
                // this.addUserForm = {
                //   // 重置添加用户表单
                //   username: "",
                //   password: "",
                //   roleType: "",
                //   description: "",
                // };
                this.$refs.addUserFormRef.resetFields();
                this.$message.success("用户添加成功！");
              }
            }).catch((error) => {
              console.error(error);
            });
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      onMouseOver(event) {
        const ev = event.target;
        const evWeight = ev.scrollWidth;
        const contentWidth = ev.clientWidth;
        if (evWeight > contentWidth) {
          this.isShowTooltip = false;
        } else {
          this.isShowTooltip = true;
        }
      },
      // 取消添加用户
      cancelAddUser() {
        this.addUserDialogVisible = false;
        // this.addUserForm = {
        //   // 重置添加用户表单
        //   username: "",
        //   password: "",
        //   roleType: "",
        //   description: "",
        // };
        this.$refs.addUserFormRef.resetFields();
      },
      // 确认更新用户
      confirmUpdateUser() {
        this.$refs.updateUserFormRef.validate((valid) => {
          if (valid) {
            const params = {
              id: this.selectedIds[0],
              username: this.updateUserForm.username,
              description: this.updateUserForm.description,
              roleType: this.updateUserForm.roleType,
            };
            this.$userManageApi.updateUser(params).then((response) => {
              if (response && response.code === 200) {
                this.updateUserDialogVisible = false;
                this.fetchUserData();
                // this.updateUserForm = {
                //   // 重置添加用户表单
                //   username: "",
                //   password: "",
                //   roleType: "",
                //   description: "",
                //   roleTypeName: "",
                // };
                this.$refs.updateUserFormRef.resetFields();
                this.$message.success(response.data);
              }
            }).catch((error) => {
              console.error(error);
            });
          } else {
            console.log('error submit!!');
            return false;
          }
        });

      },
      // 取消更新用户
      cancelUpdateUser() {
        this.updateUserDialogVisible = false;
        this.updateUserForm = {
          // 重置添加用户表单
          username: "",
          password: "",
          roleType: "",
          description: "",
          roleTypeName: "",
        };
      },
      // 确认删除用户
      confirmDeleteUser() {
        this.$confirm("此操作将永久删除该用户, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          this.$userManageApi
            .deleteUser(this.selectedIds)
            .then((response) => {
              this.fetchUserData();
              //this.deleteUserDialogVisible = false;
            })
            .catch((error) => {
              console.error(error);
            });
        });
      },
      // 确认删除用户
      confirmDeleteUserById(row) {
        // this.$confirm("此操作将永久删除该用户, 是否继续?", "提示", {
        //   confirmButtonText: "确定",
        //   cancelButtonText: "取消",
        //   type: "warning",
        // }).then(() => {
        this.$userManageApi
          .deleteUser([row.id])
          .then((response) => {
            this.fetchUserData();
          })
          .catch((error) => {
            console.error(error);
          });
        // });
      },
      // 搜索功能函数
      handleSearch() {
        this.pagination.pageNum = 1; // 搜索时重置页码
        this.fetchUserData();
      },
      // 根据用户类型搜索
      handleSearchByRoleType() {
        this.fetchUserData();
      },
      // 分页获取用户数据
      fetchUserData() {
        this.$userManageApi
          .pageGetUserInfo({
            filterKey: this.searchKeyword,
            pageSize: this.pagination.pageSize,
            pageNum: this.pagination.pageNum,
            roleType: this.roleType,
            //...this.pagination
          })
          .then((response) => {
            //console.log(response.data.records)
            this.tableData = response.data.records;
            // if (this.tableData[0].username === "superadmin") {
            //   this.tableData.splice(0, 1);
            //   // 更新分页信息
            //   this.pagination.total = response.data.total - 1;
            // }
            this.pagination.total = response.data.total;
            this.pagination.pageSize = response.data.size;
            this.fetchRoleData();

            // 遍历 tableData，检查用户状态
            this.tableData.forEach((row) => {
              if (row.userStatus === 0 || row.userStatus === 1) {
                // 更新 userStatus 变量
                this.userStatus = row.userStatus;
                // 如果只需要第一个匹配的状态，则添加 break
                // break;
              }
            });
          })
          .catch((error) => {
            console.error(error);
          });
      },
      //获取用户角色信息
      fetchRoleData() {
        this.$userManageApi
          .getAllRole()
          .then((res) => {
            this.options = res.data.map((item) => ({
              label: item.name,
              value: item.id,
            }));
            this.roleTypeMap = res.data.reduce((accumulator, role) => {
              // 将role对象的id作为属性，name作为值，添加到累加器对象中
              accumulator[role.id] = role.name;
              return accumulator;
            }, {}); // 初始化累加器为空对象
          })
          .catch((err) => {
            console.log(err);
          });
      },
      //获取用户角色数字->中文的映射表
      getRoleTypeName(roleType) {
        //scope.row.roleType 表示当前行的 roleType 属性的值
        //this.fetchRoleData()
        return this.roleTypeMap[roleType] || "未知角色";
      },
      //获取用户状态数字-
      getStatusName(userStatus) {
        const statusMap = {
          // 0启用，1禁用
          0: "启用",
          1: "禁用",
        };
        return statusMap[userStatus] || "未知状态";
      },
      handlePageChange(pageNum) {
        this.pagination.pageNum = pageNum;
        this.fetchUserData();
      },
      changeUserStatus(row) {
        if (row.userStatus === 0) {
          this.$userManageApi.updateUserStatus("1", [row.id]).then((res) => {
            if (res && res.code === 200) {
              this.fetchUserData();
              this.$message.success("启用成功");
            }
          });
        } else {
          this.$userManageApi.updateUserStatus("0", [row.id]).then((res) => {
            if (res.code === 200) {
              this.$message.success("禁用成功");
              this.fetchUserData();
            }
          });
        }
      },
      ifChooseRow(row) {
        //console.log(row)
        this.selectedIds = [];
        this.selectedIds.push(row.row.id);
        //console.log(this.selectedIds[0])
      },
      // 编辑更新用户
      editUser(row) {
        // 将当前行的数据绑定到编辑表单
        this.updateUserForm = {...row};
        //console.log(this.updateUserForm)
        if (this.updateUserForm.roleType === 1) {
          this.roleTypeName = "管理者";
        } else if (this.updateUserForm.roleType === 2) {
          this.roleTypeName = "开发者";
        } else if (this.updateUserForm.roleType === 3) {
          this.roleTypeName = "运维者";
        }
        this.updateUserDialogVisible = true;
      },
      //修改用户密码
      openEditPasswordDialog(row) {
        if (this.multipleSelection.length > 1) {
          this.updateUserDialogVisible = false;
          this.$message("抱歉，同时只能修改一条用户密码！");
        } else {
          this.editPasswordDialogVisible = true;
          this.tmpUserInfo = {...row};
        }
      },
      //添加时选择用户角色
      changeAddRoleType(val) {
        this.addUserForm.roleType = val;
      },
      //更新时选择用户角色
      changeUpdateRoleType(val) {
        //console.log(val);
        this.updateUserForm.roleType = val;
        if (val === 1) {
          this.updateUserForm.roleTypeName = "管理者";
        } else if (val === 2) {
          this.updateUserForm.roleTypeName = "开发者";
        } else if (val === 3) {
          this.updateUserForm.roleTypeName = "运维者";
        }
      },
      // 删除
      deleteSelectedRow() {
        this.confirmDeleteUser();
      },
      //关闭时候清空表单
      handleCloseDialog() {
        this.$refs.dataForm.resetFields();
      },
      confirmEditUserPassword() {
        let params = {
          id: this.tmpUserInfo.id,
          originalPassword: this.dataForm.oldpassword,
          newPassword: this.dataForm.newpassword,
        };
        this.$userManageApi
          .editUserPassword(params)
          .then((res) => {
            if (res && res.code === 200) {
              this.$message.success(res.data);
              this.editPasswordDialogVisible = false;
              this.$refs.dataForm.resetFields();
            }
          })
          .catch((err) => {
            console.log(err);
          });
      },
      resetPasswd(id) {
        this.$userManageApi
          .resetUserPassword(id)
          .then((res) => {
            if (res && res.code === 200) {
              this.$message.success(res.data);
              this.editPasswordDialogVisible = false;
              this.$refs.dataForm.resetFields();
            }
          })
          .catch((err) => {
            console.log(err);
          });
      }
    },
    //在mounted中进行异步操作使用nextTick，不然mounted中会因为组件未完全渲染就已经执行操作而报错
    mounted() {
      this.$nextTick(() => {
        this.fetchUserData();
      });
    },
  };
</script>

<style scoped>
  /* .demo-input-suffix {
        width: 600px;
      } */

  .demo-input-suffix .demo-input-align {
    margin-right: 9px; /* 调整这个值直到两个输入框对齐 */
  }

  /*.demo-input-suffix .el-select {*/
  /*  width: 80%;*/
  /*}*/

  .demo-input-suffix .el-input {
    width: 40%;
  }

  .el-select-dropdown-el-popper {
    /*max-width: 20px !important;*/
    width: 3000px !important;
  }

  .user-container {
    display: flex;
    flex-direction: column;
    /*height: 92vh;*/
    /*height: calc(100vh - 84px - 20px);*/
    margin-bottom: 10px;
    background: #eff4f9;
    background-size: cover;
    padding: 20px;
  }

  .user-header {
    width: 100%;
    height: 100px;
    margin-top: 6px;
    background-color: #fff;
    border-radius: 20px;
  }

  .title {
    display: inline-block;
    vertical-align: top;
    font-weight: 600;
    font-size: xx-large;
    padding: 20px;
  }

  .title-content {
    color: #888888;
    padding-top: 10px;
    font-size: small;
  }

  .user-operate {
    background-color: #f9fbfd;
    padding: 10px 0;
  }

  .keyword {
    padding-left: 10px;
  }

  .user-info {
    margin-top: 10px;
  }

  .right-menu {
    display: inline;
    float: right;
    margin-right: 10px;
  }

  .el-dropdown-link {
    cursor: pointer;
    color: #409eff;
  }

  .upload {
    display: flex;
    flex-direction: row;
    align-items: center;
  }

  .uploadDiv {
    padding-left: 14px;
  }

  .el-icon-arrow-down {
    font-size: 12px;
  }

  ::v-deep .el-input {
    width: 26%;
    border-radius: 6px;
    margin-right: 4px;
  }

  ::v-deep .el-image {
    margin-left: 20px;
  }

  ::v-deep .el-input--suffix {
    width: 100%;
    margin-bottom: 5px;
  }

  ::v-deep .el-table thead {
    font-size: initial;
    color: #606266;
    font-weight: 500;
  }

  ::v-deep .el-button {
    border-radius: 10px;
    display: inline-block;
  }

  ::v-deep .el-upload {
    display: block;
  }

  ::v-deep .el-pagination.is-background .el-pager li:not(.disabled).active {
    background-color: #304156;
  }
</style>
